<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <link rel="stylesheet" href="../static/plugins/layui/css/layui.css">
</head>
<style>
    .ok-body {
        padding: 10px
    }
    .layui-form-item .layui-inline {
        margin-bottom: 5px;
        margin-right: 0px;
    }
    .layui-form-pane .layui-form-label {
        width: 90px;
    }
    .layui-form-item .layui-input-inline {
        width: 170px;
    }
</style>

<body>
<div class="ok-body">

    <div class="layui-row" style="margin-top: 15px">
        <form class="layui-form layui-form-pane" action="">

            <div class="layui-form-item" style="margin-bottom: 5px;">

                <div class="layui-inline">
                    <label class="layui-form-label">指令名称</label>
                    <div class="layui-input-inline" style="margin-right: 0px;">
                        <input type="text" name="name" class="layui-input" />
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">指令状态</label>
                    <div class="layui-input-inline" style="margin-right: 0px;">
                        <select name="status">
                            <option value=""></option>
                            <option value="0">禁止</option>
                            <option value="1">待执行</option>
                            <option value="4">完成</option>>
                        </select>
                    </div>
                </div>

            </div>

            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">设备类型</label>
                    <div class="layui-input-inline" style="margin-right: 0px;">
                        <select name="modelId" lay-search>
                            <option value=""></option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">完成时间</label>
                    <div class="layui-input-inline" style="margin-right: 0px;">
                        <input type="text" name="finishTime" id="finishTime" class="layui-input" />
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">责任人</label>
                    <div class="layui-input-inline" style="margin-right: 0px;">
                        <select name="operatorId" lay-search>
                            <option value=""></option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn  layui-btn-normal" style="margin-left: 10px" lay-submit lay-filter="search">搜索
                    </button>

                    <span>
                        <button type="button" class="layui-btn layui-btn-warm" id="add" style="float: right;margin-left: 5px;">新增</button>
                        <button type="button" class="layui-btn layui-btn-danger" id="delete" style="float: right;margin-left: 60px;">删除</button>
                    </span>
                </div>

            </div>

        </form>
    </div>

    <hr class="layui-bg-orange">

    <table class="layui-hide" id="inspectionTask" lay-filter="inspectionTask"></table>
    <!--分页Div-->
    <div id="pageDiv"></div>

</div>

<script src="../static/plugins/layui/layui.js"></script>
<script src="../static/js/jquery-3.2.1.min.js"></script>
<script src="../static/js/jquery.base64.js"></script>
<script src="../static/js/device.js"></script>

<script th:inline="none">
    layui.config({
        base: '../static/plugins/layui/lay/soulTable/'
    }).extend({
        soulTable: 'soulTable'  // 模块别名
    });
    layui.use(['table', 'laypage', 'form','soulTable','laydate'], function () {
        var soulTable = layui.soulTable;
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;

        JJZ.initSelect(JJZ.named('modelId'), '/model/dataGrid', function (noError) {
            form.render();
        });

        JJZ.initSelectShowField(JJZ.named('operatorId'), '/user/dataGrid', 'username', function (noError) {
            form.render();
        });
        //完成时间
        laydate.render({
            elem: '#finishTime'
            ,format: 'yyyy-MM-dd'
        });

        var tableName = 'inspectionTask';

        var user = JJZ.currUser();

        var tableRenderObject = {
            elem: '#' + tableName
            , title: '巡检计划'
            , tableName: tableName
            ,requestUrl:'/inspectionTask/faultInspectionTask'
            , searchCol: ''
            , searchValue: ''
            ,defaultToolbar: ['filter', 'print']
            ,toolbar: true
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{title: '#', width: 50,show: 2, children:[
                        {
                            title: '巡检详情'
                            , height: 300
                            , limit: 10000000
                            , page: false
                            , data: function (d) {
                                var content = JSON.parse(d.content);
                                var result = [];
                                for(var index in content){
                                    var parts = content[index].deviceParts;
                                    for(var jndex in parts){
                                        var temp = {};
                                        temp.deviceName=content[index].deviceName;
                                        temp.devicePart=parts[jndex].partName;
                                        temp.content=parts[jndex].content;
                                        result.push(temp);
                                    }
                                }
                                return result;
                            }
                            , cols: [[
                                {type:'numbers',fixed: 'left'},
                                {field: 'deviceName', title: '设备'},
                                {field: 'devicePart', title: '部位'},
                                {field: 'content', title: '内容'},
                            ]]
                            , done: function () {
                                layui.soulTable.render(this);
                            }
                        }
                    ]
                }
                ,{field: 'name', title: '名称', align: 'center'}
                ,{field: 'description', title: '描述', align: 'center'}
                ,{title: '计划完成', align: 'center',width:142, templet: function (d) {
                        return JJZ.FormatDate(d.startTime, 'yyyy-MM-dd hh:mm');
                    }
                }
                ,{title: '实际完成', align: 'center',width:142, templet: function (d) {
                        if (d.finishTime) {
                            return JJZ.FormatDate(d.finishTime, 'yyyy-MM-dd hh:mm');
                        } else {
                            return '暂未结束';
                        }
                    }
                }
                ,{field: 'operatorName', title: '责任人',width:73, align: 'center'}
                ,{title: '班长', align: 'center',width:73, templet: function (d) {
                        if (d.monitorName) {
                            return d.monitorName;
                        } else {
                            return '未确认';
                        }
                    }
                }
                ,{title: '维修主管', align: 'center',width:87, templet: function (d) {
                        if (d.directorName) {
                            return d.monitorName;
                        } else {
                            return '未确认';
                        }
                    }
                }
                ,{field: 'status', title: '状态',width:89, align: 'center', templet: function (d) {
                        if (d.status === 0) {
                            return '<a class="layui-btn layui-btn-disabled layui-btn-xs">禁用</a>';
                        } else if (d.status === 1) {
                            return '<a class="layui-btn layui-btn-xs">待执行</a>';
                        } else if (d.status === 2) {
                            return '<a class="layui-btn layui-btn-warm layui-btn-xs">班长确认</a>';
                        } else if (d.status === 3) {
                            return '<a class="layui-btn layui-btn-warm layui-btn-xs">主管确认</a>';
                        } else if (d.status === 4) {
                            return '<a class="layui-btn layui-btn-normal layui-btn-xs">完成</a>';
                        } else if (d.status === 5) {
                            return '<a class="layui-btn layui-btn-danger layui-btn-xs">驳回</a>';
                        }
                    }
                }
                , {field: 'creatorName', align: 'center',width:73, title: '创建者'}
                , {fixed: 'right', title: '操作', align: 'center', templet: function (d) {
                        var result = '<a href="../inspectionTask/detail?id=' + d.id + '" class="layui-table-link">详情</a>&nbsp;&nbsp;';
                        if(d.status === 1){
                            result+= '<a href="javascript:JJZ.editPage(\'' + tableName + '\',' + d.id + ')" class="layui-table-link">编辑</a>&nbsp;&nbsp;';
                        }
                        if(user.organizationId === 2 && d.status === 2){
                            result+= '<a href="javascript:addComment(' + d.id +','+1+')" class="layui-table-link">班长确认</a>';
                        }
                        if(user.organizationId === 1 && d.status === 3){
                            result+= '<a href="javascript:addComment(' + d.id +','+2+')" class="layui-table-link">主管确认</a>';
                        }
                        if(user.organizationId === 3 && d.status === 1){
                            result+= '<a href="javascript:addResult(' + d.id + ')" class="layui-table-link">巡检结果</a>';
                        }
                        return result;
                    }
                }
            ]]
            ,done: function () {
                soulTable.render(this)
            }
        };

        var myTable = new JJZ.MyTable(tableRenderObject);


        form.on('submit(search)', function (data) {
            var encodeStr = $.base64.encode(JSON.stringify(data.field), 'utf-8');
            var param = 'json=' + encodeURIComponent(encodeStr);
            tableRenderObject.initParam = param;
            myTable.render();
            return false;
        });

        //批量删除数据
        $('#delete').click(function () {
            var checkStatus = table.checkStatus('inspectionTask') //idTest 即为基础参数 id 对应的值
                , data = checkStatus.data; //获取选中的数据
            layer.confirm('确认删除？', function (index) {
                myTable.delete(data);
                myTable.render();
                layer.close(index);
            });
        });

    });

    function addResult(id) {
        layer.open({
            type: 2
            , content: ['../inspectionTask/addResult?id=' + id, 'no']
            , area: ['500px', '300px']
        });
    }

    function addComment(id,type) {
        layer.open({
            type: 2
            , content: ['../inspectionTask/addComment?id=' + id+'&type='+type, 'no']
            , area: ['478px', '448px']
        });
    }

</script>
</body>
</html>